package com.kerrykidz.system.controller;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.kerrykidz.common.PrimaryKeyGenerator;
import com.kerrykidz.system.dao.model.SysHolidayEntity;
import com.kerrykidz.system.service.ISysHolidayService;
import com.kerrykidz.system.util.UserUtil;
import com.rdp.framework.exception.RDPException;

@RequestMapping("holiday")
@Controller
public class SysHolidayController {
	@Autowired
	ISysHolidayService iSysHolidayService;
	
	@RequestMapping("/sysHoliday")
	public ModelAndView sysHoliday(){
		ModelAndView mv = new ModelAndView("system/system_jiejia");
		return mv;
		
	}
	
	/**
	 * 查找相关年份假期
	 * @param 
	 * @return
	 * @throws RDPException
	 * @date: 2014年9月22日
	 */
	@RequestMapping("/findHoliday")
	@ResponseBody
	public SysHolidayEntity findHoliday(SysHolidayEntity entity)throws RDPException{
		return iSysHolidayService.findHoliday(entity);
	}
	
	/**
	 * 编辑假期
	 * @param 
	 * @return
	 * @throws RDPException
	 * @throws UnsupportedEncodingException 
	 * @date: 2014年9月22日
	 */
	@RequestMapping("/updateByPrimaryKey")
	@ResponseBody
	public String updateByPrimaryKey(SysHolidayEntity entity)throws RDPException, UnsupportedEncodingException{
		String modiBy = UserUtil.getUserFromSession().getUserId();
		String hldName = URLDecoder.decode(entity.getHldName(),"UTF-8");
		String hldAbbr = URLDecoder.decode(entity.getHldAbbr(),"UTF-8");
		entity.setModiBy(modiBy);
		entity.setHldName(hldName);
		entity.setHldAbbr(hldAbbr);
		iSysHolidayService.updateByPrimaryKey(entity);
		return "success";
	}
	
	/**
	 * 删除假期
	 * @param 
	 * @return
	 * @throws RDPException
	 * @date: 2014年9月22日
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public String delete(SysHolidayEntity entity) throws RDPException{
		iSysHolidayService.deleteByPrimaryKey(entity);
		return"success";
	}
	
	/**
	 * 添加假期
	 * @param 
	 * @return
	 * @throws RDPException
	 * @throws UnsupportedEncodingException 
	 * @date: 2014年9月22日
	 */
	@RequestMapping("/addHld")
	@ResponseBody
	public String addHld(SysHolidayEntity entity) throws RDPException, UnsupportedEncodingException{
		String modiBy = UserUtil.getUserFromSession().getUserId();
		String hldName = URLDecoder.decode(entity.getHldName(),"UTF-8");
		String hldAbbr = URLDecoder.decode(entity.getHldAbbr(),"UTF-8");
		entity.setModiBy(modiBy);
		entity.setHldName(hldName);
		entity.setHldAbbr(hldAbbr);
		String pkHldId = PrimaryKeyGenerator.getRandomPrimaryKey();
		entity.setPkHldId(pkHldId);
		iSysHolidayService.saveEntity(entity);
		return "success";
	}
}
